﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>关键词申请管理</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <link rel="stylesheet" type="text/css" href="/static/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="static/files/关键词申请管理/styles.css"/>
    <script src="static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.easyui.min.js"></script>
    <script src="../../static/files/关键词申请管理/data.js"></script>
    <script type="text/javascript" src="/static/js/easyui-lang-zh_CN.js"></script>
  </head>
  <body>
   <div>
     <div id="div1">
       <p>关键词 : <input id="gjc" type="text" value=""> <img id="tubuttn" src="../../static/images/关键词申请管理/u46.png"></p>
     </div>
     <div id="div2">
       <table id="dg2"></table>
     </div>
   </div>

   <div id="dd" class="easyui-dialog" title="开通【APP】" style="width:500px;position:relative;top:1px;"
        data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#up'">
     <h2 style="width:100px;position:relative;left:40%">开通APP</h2>
     <form id="ff" style="padding: 10px;">
       <div style="margin-bottom:20px;border-top:solid grey 1px;padding-top:15px">
         <input class="easyui-textbox" label="登录账号:" name="userCode" id="userCode"
                validType="remote['/LoginUserCode','userCode']"  invalidMessage="原账号不正确"  style="width:40%;">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <input class="easyui-textbox" label="登录账号:" name="password" id="password"
                validType="remote['/LoginPassword','password']"  invalidMessage="原密码不正确"  style="width:40%;">
       </div>
       <div style="margin-bottom:20px;border-bottom:solid grey 1px;">
         <p>关键词：<i class="guan"></i> <span style="position:relative;left:37%">企业名称：<i id="qymc"></i></span></p>
         <p>价格：<i id="jg"></i> <span style="position:relative;left:40%">服务类型：<i class="fwlx"></i></span></p>
         <input id="keyid" type="hidden" value=""/>
       </div>
     </form>
   </div>
   <div id="up">
     <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="kaiApp()">开通APP</a>
     <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
        onclick="$('#dd').dialog('close')">取消</a>
   </div>

   <!-----------------------------------------------------续费----------------------------------------------->

   <div id="gg" class="easyui-dialog" title="当前为【续费】操作" style="width:500px;position:relative;top:1px;"
        data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true,buttons:'#but'">
     <h4 style="width:300px;position:relative;left:20px">为<span class="guan"></span>续费 &nbsp;&nbsp;【当前账户余额：￥<span id="yue" style="color:red"></span>】</h4>
     <form id="hh" style="padding: 10px;">
      <p>客户名称：<input type="text" id="kehu" value="" style="color:green;margin-left:50px;width:300px" disabled="disabled"></p>
      <p>关键词：<input class="guan" style="margin-left:63px;width:200px" type="text" value="" disabled="disabled" ></p>
         服务类别：<select class="fwlx" id="fwlx" name="serviceyears" style="margin-left:50px;width:170px" onchange="jiSuanJiaGe()">
             <option value="上传苹果商城">上传苹果商城</option>
             <option value="不上传苹果商城">不上传苹果商城</option>
         </select>
         <br/><br/>
         服务年限：<select id="yer" name="serviceyears" style="margin-left:50px;width:170px" onchange="jiSuanJiaGe()">
             <option value="1">1年</option>
             <option value="2">2年</option>
             <option value="3">3年</option>
             <option value="4">4年</option>
             <option value="5">5年</option>
             <option value="6">6年</option>
             <option value="7">7年</option>
             <option value="8">8年</option>
             <option value="9">9年</option>
             <option value="10">10年</option>
         </select>
      <p>价格：<input id="jiage" style="margin-left:78px;width:230px" type="text" value=""  disabled="disabled"></p>
     </form>
   </div>

   <div id="but">
     <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="xufei()">续费提交</a>
     <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"
        onclick="$('#gg').dialog('close')">取消</a>
   </div>
  </body>
  <script>
    var keywords;
    show(keywords);
    $("#tubuttn").click(function () {
        keywords = $("#gjc").val();
        show(keywords);
    })
    function show(keywords) {
        if(keywords == "" || keywords == null){
            keywords = "";
        }
        // 显示关键词申请管理详情
        $('#dg2').datagrid({
            url: '/keyWordManShow?keywords='+keywords,
            pagination: true,// 分页工具
            pageSize: 10,
            pageList: [5, 10, 15, 20, 50],// 每页可显示条数
            fitColumns: true,// 拉宽
            singleSelect:true,
            // fit: true,  // 拉高度
            toolbar: ".wu-toolbar-button",
            columns: [[
                {field: 'id', title: '序号',width: 40},
                {field: 'keywords', title: '关键词', width:80},
                {field: 'customname', title: '客户名称', width: 80},
                {field: 'agentname', title: '代理商', width: 80},
                {field: 'serviceyears', title: '申请年限', width: 50},
                {field: 'preregdatetime', title: '申请日期', width: 100},
                {field: 'regpassdatetime', title: '到期日期', width: 100},
                {field: 'ispass', title: '申请到期状态', width: 60, formatter:function (ispass) {
                    return ispass==0 ? '<span style="color:green;">未过期</span>': ispass ==1? '<span style="color:gold;">快过期</span>':'<span style="color:red">已过期</span>';}},
                {field: 'checkstatus', title: '审核状态', width: 60, formatter:function (checkstatus) {
                    return checkstatus==0 ? "<span style=\"color:green;\">已申请</span>": checkstatus ==1? "<span style=\"color:gold;\">审核中</span>": checkstatus==2 ? "<span style=\"color:blue\">已通过</span>":"<span style=\"color:red\">未通过</span>";}},
                {field: 'isuse', title: '使用状态', width: 60, formatter:function (isuse) {
                    return isuse==0 ? '<span style="color:gold;">未使用</span>':'<span style="color:green;">已使用</span>';}},
                {field: 'openapp', title: '使用状态', width: 60, formatter:function (openapp) {
                    return openapp==0 ? '<span style="color:red;">未开通</span>':'<span style="color:green;">已开通</span>';}},
                {field:'sss',title: '操作', width:100, formatter:function (id, row, rowIndex) {
                    return (row.openapp==0?"<a href='#' onclick='openApp("+row.id+")' style='color:green'>开通APP</a>":"")+"  <a href='#' onclick='openxufei("+row.id+")' style='color:blue'>续费</a>";
                }}
            ]]
        });
    }

    //----------------------------开通APP----------------------//
    function openApp(id) { //打开弹框
        $.ajax({
            url:"openAppId",
            data:"id="+id,
            type:"POST",
            dataType:"json",
            success:function(asKeywords){
                zhanshi(asKeywords);
            },
            error:function(){
                alert("出错了");
            }
        });
        $("#dd").dialog('open');
    }

    //
    function zhanshi(asKeywords) {
        $(".guan").html(asKeywords.keywords);
        $("#qymc").html(asKeywords.customname);
        $("#jg").html(asKeywords.price);
        $("#keyid").val(asKeywords.id);
        $(".fwlx").html(asKeywords.id == 12 ? "上传苹果商城":"不上传苹果商城");
    }

    function kaiApp() {
        var userCode = $("#userCode").val();
        var password = $("#password").val();
        var id = $("#keyid").val();
        $.ajax({
            url:"kaiApp",
            data:"userCode="+userCode+"&password="+password+"&id="+id,
            type:"POST",
            dataType:"json",
            success:function(count){
              if(count > 0){
                  $("#dd").dialog('close');
                  show(keywords);
                  $.messager.show({
                      title: '操作提示',
                      msg: '开通APP成功！',
                      timeout: 1000,
                      showType: 'slide'
                  });
              }else{
                  $.messager.show({
                      title: '操作提示',
                      msg: '登录名或密码错误！',
                      timeout: 1000,
                      showType: 'slide'
                  });
              }
            },
            error:function(){
                $.messager.show({
                    title: '操作提示',
                    msg: '开通APP失败！',
                    timeout: 1000,
                    showType: 'slide'
                });
            }
        });
    }

    //----------------------------续费-------------------------//

    function openxufei(id) {
        $.ajax({
            url:"openAppId",
            data:"id="+id,
            type:"POST",
            dataType:"json",
            success:function(asKeywords){
                xufeiShow(asKeywords);
            },
            error:function(){
                alert("出错了");
            }
        });
        $("#gg").dialog('open');
    }

    function xufeiShow(asKeywords){
        $(".guan").val(asKeywords.keywords);
        $("#kehu").val(asKeywords.agentname);
        $(".fwlx").val(asKeywords.id == 12 ? "上传苹果商城":"不上传苹果商城");
        $("#yer").val(asKeywords.serviceyears);
        jiSuanJiaGe();
    }

    function jiSuanJiaGe(){
        var configTypeName = $("#fwlx").val();
        $.ajax({
            url:"waiAppId",
            data:"configTypeName="+configTypeName,
            type:"POST",
            dataType:"json",
            success:function(asSystemconfig){
                var yer = $("#yer").val();
                var qian = asSystemconfig.configvalue;
                var count = yer*qian;
                $("#jiage").val(count);
            },
            error:function(){
                alert("出错了");
            }
        });
    }
    
    function xufei() {
        var keywords = $(".guan").val();
        var serviceYears = $("#yer").val();
        var price = $("#jiage").val();
        $.ajax({
            url:"xufei",
            data:"keywords="+keywords+"&serviceYears="+serviceYears+"&price="+price,
            type:"POST",
            dataType:"json",
            success:function(count){
                if(count > 0){
                    $("#gg").dialog('close');
                    show("");
                    $.messager.show({
                        title: '操作提示',
                        msg: '续费成功！',
                        timeout: 1000,
                        showType: 'slide'
                    });
                }else{
                    $.messager.show({
                        title: '操作提示',
                        msg: '续费失败！',
                        timeout: 1000,
                        showType: 'slide'
                    });
                }
            },
            error:function(){
                $.messager.show({
                    title: '操作提示',
                    msg: '出现错误！',
                    timeout: 1000,
                    showType: 'slide'
                });
            }
        });
    }

  </script>
</html>
